package com.groupbuying.admin.utils;

import com.groupbuying.admin.domain.SysAgentInfoDO;
import org.apache.commons.lang3.StringUtils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class AgentInfoCheckUtils {

    public static final String PHONE = "^(((13|18)[0-9]{9})|(15[012356789][0-9]{8})|((147|170|171|173|175|176|177|178)[0-9]{8}))$";

    public static boolean chackAgentParams(SysAgentInfoDO agentInfo){
        if(StringUtils.isEmpty(agentInfo.getAgentNo())){
            return false;
        }
        if(StringUtils.isEmpty(agentInfo.getAgentName())){
            return false;
        }
        if(StringUtils.isEmpty(agentInfo.getPassword())){
            return false;
        }
        if(StringUtils.isEmpty(agentInfo.getLeaderName())){
            return false;
        }
        if(StringUtils.isEmpty(agentInfo.getLeaderPhone())){
            return false;
        }
        if(StringUtils.isEmpty(agentInfo.getProvince())){
            return false;
        }
        if(StringUtils.isEmpty(agentInfo.getCity())){
            return false;
        }
        return true;
    }

    public static boolean editChackAgentParams(SysAgentInfoDO agentInfo){
        if(StringUtils.isEmpty(agentInfo.getId())){
            return false;
        }
        if(StringUtils.isEmpty(agentInfo.getAgentName())){
            return false;
        }
        if(StringUtils.isEmpty(agentInfo.getPassword())){
            return false;
        }
        if(StringUtils.isEmpty(agentInfo.getLeaderName())){
            return false;
        }
        if(StringUtils.isEmpty(agentInfo.getLeaderPhone())){
            return false;
        }
        return true;
    }

    public static boolean checkAgentName(String name){
        String regEx = "[ _`~!@#$%^&*+=|{}':;',\\[\\].<>/?~！@#￥%……&*——+|{}【】‘；：”“’。，、？]|\n|\r|\t";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(name);
        return m.find();
    }

    public static boolean checkAgentLeaderName(String name){
        String regEx = "[ _`~!@#$%^&*()+=|{}':;',\\[\\].<>/?~！@#￥%……&*（）——+|{}【】‘；：”“’。，、？]|\n|\r|\t";
        Pattern p = Pattern.compile(regEx);
        Matcher m = p.matcher(name);
        return m.find();
    }

    /**
     * 判断是否有汉字
     */
    public static boolean isHashChinese(String name){
        // 汉字的Unicode取值范围
        String regex = "[\u4e00-\u9fa5]";
        Pattern pattern = Pattern.compile(regex);
        Matcher match = pattern.matcher(name);
        return match.find();
    }

    public static final boolean isMoblie(String mobile){
        boolean flag = false;
        if (null != mobile && !mobile.trim().equals("") && mobile.trim().length() == 11) {
            Pattern pattern = Pattern.compile(PHONE);
            Matcher matcher = pattern.matcher(mobile.trim());
            flag = matcher.matches();
        }
        return flag;
    }
}
